package org.dev.vlp.controller;

import org.dev.vlp.bean.JsonResponse;
import org.dev.vlp.constants.Roles;
import org.dev.vlp.interceptor.RequiredPermission;
import org.dev.vlp.service.WordService;
import org.dev.vlp.vo.VocabularyEstimationVo;
import org.dev.vlp.vo.VocabularyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * Description
 * Param
 * return
 * Author:86184
 * Date: 2023/1/17
 */
@RestController
@RequestMapping("/estimation")
@RequiredPermission({Roles.ROLE_USER})
public class EstimationController extends BaseController{
    @Autowired
    private WordService wordService;

    @GetMapping("/listEstimationWords")
    public JsonResponse<Object> listEstimationWords() {
        long start = System.currentTimeMillis();
        VocabularyEstimationVo estimation = wordService.listEstimationWords((int)getUid());
        System.out.println("耗时: " + (System.currentTimeMillis() - start));
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("item", estimation);
        return JsonResponse.success(hashMap);
    }

    @PostMapping("/calculate")
    public JsonResponse<Object> calculate(@RequestBody List<Integer> levelRightCounts) {
        VocabularyVo vocabularyVo = wordService.calculate(getUid(),levelRightCounts);
        return JsonResponse.success(vocabularyVo);
    }
}
